package gold.digger;

import gold.utils.InputUtil;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC447 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int numberOfBoomerangs(int[][] points) {
            int count = 0;
            for (int i = 0; i < points.length; i++) {
                Map<Integer, Integer> intMap = new HashMap<Integer, Integer>();
                for (int j = 0; j < points.length; j++) {
                    if (i == j) continue;
                    int curDis = getDis(points[i], points[j]);
                    intMap.put(curDis, intMap.getOrDefault(curDis, 0) + 1);
                }
                for (Integer disCount : intMap.values()) {
                    count += disCount * (disCount - 1);
                }
            }

            return count;
        }

        public int getDis(int[] p1, int[] p2) {
            return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[][] arr = InputUtil.toDoubleIntegerArray("[[0,0],[1,0],[2,0]]");
        System.out.println(solution.numberOfBoomerangs(arr));
    }

    public static void main(String[] args) throws Exception {
        LC447 an = new LC447();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
